package com.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * 401. 二进制手表
 * 二进制枚举
 *
 * @author fy
 * @date 2022/5/5 9:16
 */
public class Solution401_2 {

    public List<String> readBinaryWatch(int turnedOn) {
        List<String> ans = new ArrayList<String>();
        for (int i = 0; i < 1024; ++i) {
            // 用位运算取出高 4 位和低 6 位
            int h = i >> 6, m = i & 63;
            if (h < 12 && m < 60 && Integer.bitCount(i) == turnedOn) {
                ans.add(h + ":" + (m < 10 ? "0" : "") + m);
            }
        }
        return ans;
    }

}
